package com.li.jiang.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.li.jiang.obj.pojo.*;
import com.li.jiang.mapper.ResumeMapper;
import com.li.jiang.obj.vo.ResumeVO;
import com.li.jiang.service.IResumeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 用户基本简历表 服务实现类
 * </p>
 *
 * @author 李江
 * @since 2024-04-12
 */
@Service
public class ResumeServiceImpl extends ServiceImpl<ResumeMapper, Resume> implements IResumeService {

    @Autowired
    private CampusActionServiceImpl campusActionService;

    @Autowired
    private JobExperienceServiceImpl jobExperienceService;

    @Autowired
    private CertificateServiceImpl certificateService;

    @Autowired
    private ProjectExperienceServiceImpl projectExperienceService;
    @Override
    public ResumeVO getResumeByUid(Long uid) {
        //1.获取学生简历基本信息
        Resume resume = this.lambdaQuery().eq(Resume::getUid,uid).one();
        if (resume==null){
            return null;
        }
        //2.获取学生校园经历
        List<CampusAction> campusActions = campusActionService.lambdaQuery().eq(CampusAction::getResumeId,resume.getId()).list();
        //3.获取学生工作经历
        List<JobExperience> jobExperiences = jobExperienceService.lambdaQuery().eq(JobExperience::getResumeId,resume.getId()).list();
        //4.获取学生证书
        List<Certificate> certificates = certificateService.lambdaQuery().eq(Certificate::getResumeId,resume.getId()).list();
        //5.获取学生项目经历
        List<ProjectExperience> projectExperiences = projectExperienceService.lambdaQuery().eq(ProjectExperience::getResumeId,resume.getId()).list();

        //6.封装ResumeVO

        ResumeVO resumeVO = BeanUtil.copyProperties(resume,ResumeVO.class);

        if (CollUtil.isNotEmpty(campusActions)){
            resumeVO.setCampusAction(campusActions);
        }
        if (CollUtil.isNotEmpty(jobExperiences)){
            resumeVO.setJobExperience(jobExperiences);
        }
        if (CollUtil.isNotEmpty(certificates)){
            resumeVO.setCertificate(certificates);
        }
        if (CollUtil.isNotEmpty(projectExperiences)){
            resumeVO.setProjectExperience(projectExperiences);
        }

        return resumeVO;
    }
}
